package com.shishuo.cms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.dao.AuthorizationDao;
import com.shishuo.cms.entity.Authorization;
import com.shishuo.cms.entity.vo.PageVo;

@Service
public class AuthorizationService {

	@Autowired
	private AuthorizationDao authorizationDao;

	public Authorization addGuestbook(String name, String weixin, String url) {
		Authorization authorization=new Authorization();
		authorization.setName(name);
		authorization.setWeixin(weixin);
		authorization.setUrl(url);
		authorizationDao.addAuthorization(authorization);
		return authorization;
	}

	public int updateAuthorization(Authorization authorization) {
		return authorizationDao.updateAuthorization(authorization);
	}

	public int deleteAuthorization(long authorizationId) {
		return authorizationDao.deleteAuthorization(authorizationId);
	}

	public Authorization getAuthorizationById(long authorizationId) {
		return authorizationDao.getAuthorizationByID(authorizationId);
	}
	
	public Authorization selectByCondition(String condition){
		return authorizationDao.selectByCondition(condition);
	}

	public PageVo<Authorization> getAuthorizationPage(int pageNum,String weixin,String name) {
		PageVo<Authorization> pageVo = new PageVo<Authorization>(pageNum);
		pageVo.setRows(10);
		List<Authorization> list = authorizationDao.selectByPage( 
				pageVo.getOffset(), pageVo.getRows(),weixin,name);
		pageVo.setList(list);
		pageVo.setCount(authorizationDao.selectCountByPage(weixin,name));
		return pageVo;
	}

}
